<template>
  <div>
    <el-form ref="formRef" :model="formData" :rules="formRule" label-width="120px" style="max-width: 1000px;">
      <el-form-item label="轮播图" prop="bannerImage">
        <File-upload ref="bannerImageRef" v-model="formData.bannerImage" :fileSize="50" :limit="6" :fileType="['png', 'jpg', 'jpeg']" listType="picture-card"  img-size="750px*750px"></File-upload>
      </el-form-item>
      <el-form-item label="详情图片" prop="detailImage">
        <File-upload ref="detailImageRef" v-model="formData.detailImage" :fileSize="50" :limit="6" :fileType="['png', 'jpg', 'jpeg']" listType="picture-card"></File-upload>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import {getCurrentInstance, ref, onMounted, shallowRef, reactive, onBeforeUnmount, watch} from "vue"
import { useRouter } from "vue-router"
import FileUpload from "@components/FileUpload.vue"
const router = useRouter()
const { proxy } = getCurrentInstance()

const props = defineProps({
  detail:{
    type: Object,
    default: {},
  }
})
const formRef = ref(null)
const formData = reactive({
  bannerImage:'',
  detailImage:'',
})
watch(() => props.detail, val => {
  if (val) {
    for (let key in formData){
      formData[key] = props.detail[key];
    }
  } else {

  }
},{ deep: true, immediate: true });
onMounted(() => {
  // getClass()
})

const formRule = reactive({
  bannerImage: [{ required: true, message: "请选择轮播图", trigger: "blur" }],
  detailImage: [{ required: true, message: "请选择详情图片", trigger: "blur" }],
})

const submit = async () => {
  let flag = false;
  await formRef.value.validate((valid, fields) => {
    if (valid) {
      flag = true
    }
  })
  if(flag){
    return formData;
  }else{
    return false;
  }
}
defineExpose({
  submit
})
</script>


<style lang="less" scoped>

</style>
